//package com.example.wjy.util;
//
//import android.content.Context;
//import android.util.AttributeSet;
//import android.util.DisplayMetrics;
//import android.view.MotionEvent;
//import android.view.View;
//import android.view.WindowManager;
//import android.widget.LinearLayout;
//import android.widget.TextView;
//
//import androidx.annotation.Nullable;
//import androidx.recyclerview.widget.RecyclerView;
//
//import com.example.superyi.myteam.R;
//
//public class CustomRecyclerView extends RecyclerView {
//    //itemView的第一个childView
//    private TextView tvTitle;
//    //删除按钮
//    private TextView tvDelete;
//    //删除按钮的宽度
//    private int tvDeleteWidth;
//    //显示删除按钮的标识
//    public boolean isDeleteShow = false;
//    public int screenWidth;
//    //手指按下的位置
//    private int downX;
//    private int downY;
//    // 当前处理的item的LayoutParams
//    private LinearLayout.LayoutParams mLayoutParams;
//    public CustomRecyclerView(Context context) {
//        super(context);
//    }
//
//    public CustomRecyclerView(Context context, @Nullable AttributeSet attrs) {
//        super(context, attrs);
//        //获取屏幕宽度
//        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//        DisplayMetrics dm = new DisplayMetrics();
//        manager.getDefaultDisplay().getMetrics(dm);
//        screenWidth = dm.widthPixels;
//    }
//
//    @Override
//    public boolean onTouchEvent(MotionEvent e) {
//        int action = e.getAction();
//        switch (action){
//            case MotionEvent.ACTION_DOWN:
//                doActionDown(e);
//                break;
//            case MotionEvent.ACTION_MOVE:
//                return doActionMove(e);
//            case MotionEvent.ACTION_UP:
//                doActionUp();
//                break;
//        }
//        return super.onTouchEvent(e);
//    }
//    private void doActionDown(MotionEvent e) {
//        if(isDeleteShow) {
//            backToNormal();
//        }
//        //获取按下时的坐标x、y
//        downX = (int)e.getX();
//        downY = (int)e.getY();
//
//        //1、获取当前点的item,Recyclerview没有ListView的pointToPosition(int downX,int downY) - getFirstVisiblePosition;
//        //int firstPos = ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();//首个可见itemView
//        //int lastPos = ((LinearLayoutManager)getLayoutManager()).findLastVisibleItemPosition();//最后一个可见itemView
//        //通过position得到当前点的itemView
//        View itemView = findChildViewUnder(e.getX(),e.getY());
//        RecyclerViewDeleteAdapter.MyViewHolder viewHolder = (RecyclerViewDeleteAdapter.MyViewHolder) getChildViewHolder(itemView);
//        itemView = viewHolder.itemView;
//        tvDelete = (TextView) itemView.findViewById(R.id.tv_delete);
//        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
//        //2、获取删除按钮的宽度
//        tvDeleteWidth = tvDelete.getLayoutParams().width;
//        mLayoutParams = (LinearLayout.LayoutParams) tvTitle.getLayoutParams();
//        mLayoutParams.width = screenWidth;
//        tvTitle.setLayoutParams(mLayoutParams);
//    }
//    private boolean doActionMove(MotionEvent e) {
//        //计算偏移量
//        int scrollX = (int)(e.getX() - downX);
//        int scrollY = (int) (e.getY() - downY);
//        //比较上下滑动与左右滑动的偏移量
//        if(Math.abs(scrollX) - Math.abs(scrollY) > 0){
//            //左右滑动
//            if(e.getX() < downX) {
//                //向左滑动
//                if (-(scrollX / 2)>= tvDeleteWidth ) {
//                    scrollX = -tvDeleteWidth;
//                }
//                //重新设置第一个childView的左边距
//                mLayoutParams.leftMargin = scrollX;
//                tvTitle.setLayoutParams(mLayoutParams);
//            }
//            return true;
//        }
//        //上下滑动交由父view处理
//        return super.onTouchEvent(e);
//    }
//    private void doActionUp() {
//        // 偏移量大于按钮尺寸的一半，则显示
//        if(-mLayoutParams.leftMargin >= tvDeleteWidth / 2) {
//            mLayoutParams.leftMargin = -tvDeleteWidth;
//            //给显示按钮的标识赋值
//            isDeleteShow = true;
//        }else {
//            // 否则恢复默认
//            backToNormal();
//        }
//        tvTitle.setLayoutParams(mLayoutParams);
//    }
//    public void backToNormal(){
//        //重新设置第一个childView的左边距
//        mLayoutParams.leftMargin = 0;
//        tvTitle.setLayoutParams(mLayoutParams);
//        isDeleteShow = false;
//    }
//
//
//}
